<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"      
      xmlns:sec="http://www.springframework.org/security/tags"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:body>
        <ui:composition>
            <script type="text/javascript" src="js/jquery-1.7.1.min.js"/>
            <script>
                
                function toggleUserInfoPanel() {
                    $("#userInfoPanel").slideToggle(100, function(){});
                };
                
                $(document).ready(function() {
                    $("#userInfoButton").click(toggleUserInfoPanel
                    );
                });
            </script>
            <div class="header">
                <h:link value="Home" outcome="/index" />
                |
                        
                <div class="userInfoButtonWrapper">
                    <div id="userInfoButton">
                        <div style="margin: 0px; padding: 0px; display: inline; top:0px; float: left;">
                            <c:choose>
                                <c:when test="#{not empty request.userPrincipal}">
                                    Logged as: <b>#{request.userPrincipal.name}</b>
                                </c:when>
                                <c:otherwise>
                                    Not logged in
                                </c:otherwise>      
                            </c:choose>
                        </div>
                        &nbsp;&nbsp;<img style="display: inline;" src="images/gear_18x18.png" />
                    </div>
                    <div id="userInfoPanel">
                        <c:choose>
                            <c:when test="#{ not empty request.userPrincipal}">
                                <table style="width: 98%;">

                                <tr>
                                    <td>
                                        User name:
                                    </td>
                                    <td>
                                        #{request.userPrincipal.name}
                                    </td>
                                </tr>
                                <tr><td>Roles: </td></tr>
                                <tr>
                                    <td>
                                        <c:forEach items="#{loginBean.roles}" var="item">
                                            &nbsp;&nbsp;#{item.authority}<br />
                                        </c:forEach>   
                                    </td>                                    
                                </tr>
                                <tr>
                                    <td colspan="2"><hr /></td>
                                </tr>
                                <tr>
                                    <td colspan="2" style="text-align: right; ">
                                        <h:form>
                                            <h:commandLink class="logoutLink" actionListener="#{loginBean.logout}" value="Logout" />
                                        </h:form>
                                    </td>
                                </tr>
                            </table>                                     
                            </c:when>
                            <c:otherwise>                                    
                                <h:form id="panelLoginForm" >
                                    <h:panelGrid columns="1">
                                        <h:outputLabel value="User Name" for="j_username"/>
                                        <h:inputText id="j_username"
                                                    value="#{loginBean.username}" size="24"
                                                    maxlength="80" required="true"/>
                                        <h:outputLabel value="Password" for="j_password"/>
                                        <h:inputSecret id="j_password"
                                                        value="#{loginBean.password}" size="24"
                                                        maxlength="80" required="true"/>
                                    </h:panelGrid>
                                    <h:commandButton actionListener="#{loginBean.login}" value="Login"/>

                                    <h:messages style="color: red;"/>
                                </h:form>
                            </c:otherwise>
                        </c:choose>
                        <div style="width: 100%; 
                                    height: 10px; 
                                    text-align: center;
                                    border-top: 1px solid dodgerblue; 
                                    margin-top: 4px;
                                    cursor: pointer;"
                                    onclick="toggleUserInfoPanel()">
                            ^^^
                        </div> 
                    </div>
                </div>
                    
             </div>
        </ui:composition>        
    </h:body>
</html>

